package com.tianma315.admin.agent.view;

import com.tianma315.admin.agent.domain.AgentAddressDO;
import com.tianma315.admin.agent.domain.AgentDO;
import com.tianma315.admin.agent.service.AgentAddressService;
import com.tianma315.admin.agent.service.AgentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/agent/view")
public class AgentViewController {

    @Autowired
    private AgentService agentService;
    @Autowired
    private AgentAddressService agentAddressService;

    @GetMapping()
    @RequiresPermissions("agent:list")
    String Agent() {
        return "agent/agent";
    }


    @GetMapping("/add")
    @RequiresPermissions("agent:add")
    String add() {
        return "agent/add";
    }


    @GetMapping("/edit/{agentId}")
    @RequiresPermissions("agent:edit")
    String edit(@PathVariable("agentId") Long agentId, Model model) {
        AgentDO agent = agentService.getById(agentId);
        AgentAddressDO agentAddressDO = agentAddressService.getAgentAddressByAgentId(agentId.intValue());
        model.addAttribute("agent", agent);
        model.addAttribute("agentAddress",agentAddressDO);
        return "agent/edit";
    }


}
